package com.liuhaoqi.raletiveblog.controller;

import com.liuhaoqi.raletiveblog.entity.Blog;
import com.liuhaoqi.raletiveblog.entity.User;
import com.liuhaoqi.raletiveblog.service.CategoryService;
import com.liuhaoqi.raletiveblog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Author liuhaoqi
 * @Date 2020/4/28 15:26
 * @Version 1.0
 */
@Controller
public class AdminController {
    @Autowired
    UserService userService;
    @Autowired
    CategoryService categoryService;

    /**
     * 登录
     * @param username
     * @param password
     * @param model
     * @return
     */
    @PostMapping("/checkUser")
    public String checkUser(@RequestParam("username") String username,
                            @RequestParam("password") String password, Model model) {
        User user = userService.checkUser(username, password);
        if (user == null) {
            model.addAttribute("message", "用户名密码错误!");
            return "admin/login";
        } else {
            model.addAttribute("user",user);
            return "admin/index";
        }
    }

    @GetMapping("/admin/adminMsg")
    public String getAdminMsg(Model model) {
        List<User> userMsg = userService.getUserMsg();
        model.addAttribute("userMsg",userMsg);
        return "admin/adminMsg";
    }

    @GetMapping("/admin/setWeb")
    public String setWeb(Model model) {
        return "admin/setWeb";
    }

    @GetMapping("/admin/friendlinks")
    public String friendlinks(Model model) {
        return "admin/friendlinks";
    }

    @GetMapping("/admin/log")
    public String log(Model model) {
        return "admin/log";
    }

    @GetMapping("/admin/Users")
    public String getUsersInfo(Model model) {
        return "admin/Users";
    }

    @GetMapping("/admin/PwdSet")
    public String pwdSet(Model model) {
        return "admin/PwdSet";
    }

    @GetMapping("/admin/welcome")
    public String getWelcome(Model model) {
        return "admin/welcome";
    }


    @GetMapping("/admin/commentMang")
    public String commentMang(Model model) {
        return "admin/commentMang";
    }

    @GetMapping("/admin/sortManager")
    public String sortManager(Model model) {
        return "admin/sortManager";
    }

    @GetMapping("/admin/layer_model4")
    public String tolayer_model4(Model model) {
        return "admin/layer_model4";
    }

    @GetMapping("/admin/categoryMang")
    public String categoryMang(Model model) {
        return "admin/categoryMang";
    }

    @GetMapping("/admin/resourceMang")
    public String resourceMang(Model model) {
        return "admin/resourceMang";
    }

    @GetMapping("/admin/timelineMang")
    public String timelineMang(Model model) {
        return "admin/timelineMang";
    }

    @GetMapping("/admin/layer_model5")
    public String tolayer_model5() {
        return "admin/layer_model5";
    }

    @GetMapping("/admin/layer_model6")
    public String tolayer_model6() {
        return "admin/layer_model6";
    }


}
